//
//  BZThreadQueue.m
//  MZBasic
//
//  Created by Sings on 2023/7/6.
//

#import "BZThreadQueue.h"

#define ICONCURRENCYCOUNT 1

@interface BZThreadQueue ()

@property (nonatomic, strong, readwrite) NSMutableArray<BZThreadQueueTask *> *marTask;

@end

@implementation BZThreadQueue

- (NSMutableArray<BZThreadQueueTask *> *)marTask {
    if (_marTask == nil) {
        _marTask = [NSMutableArray array];
    }
    return _marTask;
}

- (instancetype) init {
    if (self = [super init]) {
        self.iConcurrency = ICONCURRENCYCOUNT;
    }
    return self;
}

- (void)setIConcurrency:(NSUInteger)iConcurrency {
    if (iConcurrency < 1) {
        iConcurrency = ICONCURRENCYCOUNT;
    }else {
        _iConcurrency = iConcurrency;
    }
}

- (NSString *)strLabel {
    if (_strLabel == nil) {
        NSDateFormatter * formatter = [[NSDateFormatter alloc ] init];
        [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss:SSS"];
        int x = arc4random() % 100;
        int x1 = arc4random() % 100+100;
        _strLabel = [NSString stringWithFormat:@"%@%d%d",[formatter stringFromDate:[NSDate date]],x,x1];
    }
    return _strLabel;
}

- (void)addTask:(BZThreadQueueTask *)task {
    [self.marTask addObject:task];
}


@end


@interface BZThreadQueueTask ()

@property (nonatomic, readwrite, copy) BZThreadQueueTaskBlock task;

@end

@implementation BZThreadQueueTask

- (instancetype) initWithAction:(BZThreadQueueTaskBlock) task {
    if (self = [super init]) {
        self.task = task;
    }
    return self;
}
@end
